/*
 * Created by JFormDesigner on Sat Dec 24 09:29:21 CST 2022
 */

package num2;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

import com.jgoodies.forms.factories.*;

/**
 * @author 1
 */
public class WinA extends JFrame implements ActionListener, ItemListener {
    public static void main(String[] args) {
        WinA winA = new WinA();
        winA.setVisible(true);
    }
    public WinA() {
        initComponents();
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        DefaultComponentFactory compFactory = DefaultComponentFactory.getInstance();
        panel1 = new JPanel();
        label2 = compFactory.createLabel("\u5b66\u53f7\uff1a");
        studentId = new JTextField();
        label1 = compFactory.createLabel("\u59d3\u540d\uff1a");
        name = new JTextField();
        panel6 = new JPanel();
        panel10 = new JPanel();
        panel11 = new JPanel();
        panel2 = new JPanel();
        panel4 = new JPanel();
        label4 = compFactory.createLabel("\u52a9\u5b66\u91d1\u7b49\u7ea7\uff1a");
        moneyLevel = new JComboBox();
        moneyLevel.addItem("三等");
        moneyLevel.addItem("二等");
        moneyLevel.addItem("一等");
        moneyLevel.addItemListener(this);
        panel5 = new JPanel();
        label5 = compFactory.createLabel("\u52a9\u5b66\u91d1\uff1a");
        show = new JTextField();
        show.setText("3000");
        show.addActionListener(this);
        panel7 = new JPanel();
        add = new JButton();
        add.addActionListener(this);
        save = new JButton();
        edit = new JButton();
        panel3 = new JPanel();
        label3 = compFactory.createLabel("\u6027\u522b\uff1a");
        radioButton1 = new JRadioButton();
        radioButton2 = new JRadioButton();
        scrollPane2 = new JScrollPane();
        table1 = new JTable();
        Object[] ColumnNames = {"学号", "姓名", "性别","助学金等级","助学金"};
        Model = new DefaultTableModel(RowData, ColumnNames) {
            @Override
            public boolean isCellEditable(int row, int column) { // 表格不可编辑
                return false;
            }
        };
        table1.setModel(Model);

        //======== this ========
        setTitle("\u5b66\u751f\u52a9\u5b66\u91d1\u5f55\u5165\u7cfb\u7edf");
        setMinimumSize(new Dimension(432, 459));
        Container contentPane = getContentPane();
        contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 25, 10));

        //======== panel1 ========
        {
            panel1.setLayout(new GridLayout(2, 1));

            //---- label2 ----
            label2.setHorizontalAlignment(SwingConstants.CENTER);
            panel1.add(label2);
            panel1.add(studentId);

            //---- label1 ----
            label1.setHorizontalAlignment(SwingConstants.CENTER);
            panel1.add(label1);
            panel1.add(name);
        }
        contentPane.add(panel1);

        //======== panel6 ========
        {
            panel6.setLayout(new BorderLayout());

            //======== panel10 ========
            {
                panel10.setLayout(new BorderLayout());
            }
            panel6.add(panel10, BorderLayout.WEST);

            //======== panel11 ========
            {
                panel11.setLayout(new BorderLayout());
            }
            panel6.add(panel11, BorderLayout.EAST);
        }
        contentPane.add(panel6);

        //======== panel2 ========
        {
            panel2.setLayout(new GridLayout(4, 1));

            //======== panel4 ========
            {
                panel4.setLayout(new GridLayout());
                panel4.add(label4);
                panel4.add(moneyLevel);
            }
            panel2.add(panel4);

            //======== panel5 ========
            {
                panel5.setLayout(new GridLayout());
                panel5.add(label5);

                //---- show ----
                show.setEditable(false);
                panel5.add(show);
            }
            panel2.add(panel5);

            //======== panel7 ========
            {
                panel7.setLayout(new FlowLayout());

                //---- add ----
                add.setText("\u6dfb\u52a0");
                panel7.add(add);

                //---- save ----
                save.setText("\u4fdd\u5b58");
                panel7.add(save);

                //---- edit ----
                edit.setText("\u9000\u51fa");
                panel7.add(edit);
                edit.addActionListener(this);
            }
            panel2.add(panel7);

            //======== panel3 ========
            {
                panel3.setLayout(new FlowLayout());
                panel3.add(label3);

                //---- radioButton1 ----
                radioButton1.setText("\u7537");
                panel3.add(radioButton1);

                //---- radioButton2 ----
                radioButton2.setText("\u5973");
                panel3.add(radioButton2);
            }
            panel2.add(panel3);
        }
        contentPane.add(panel2);

        //======== scrollPane2 ========
        {
            scrollPane2.setMinimumSize(new Dimension(1, 1));
            scrollPane2.setViewportView(table1);
        }
        contentPane.add(scrollPane2);
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JPanel panel1;
    private JLabel label2;
    private JTextField studentId;
    private JLabel label1;
    private JTextField name;
    private JPanel panel6;
    private JPanel panel10;
    private JPanel panel11;
    private JPanel panel2;
    private JPanel panel4;
    private JLabel label4;
    private JComboBox moneyLevel;
    private JPanel panel5;
    private JLabel label5;
    private JTextField show;
    private JPanel panel7;
    private JButton add;
    private JButton save;
    private JButton edit;
    private JPanel panel3;
    private JLabel label3;
    private JRadioButton radioButton1;
    private JRadioButton radioButton2;
    private JScrollPane scrollPane2;
    private JTable table1;
    private DefaultTableModel Model;
    private Object[][] RowData;

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==add) {
            if(studentId.getText().equals("") || name.getText().equals("")) {
                System.out.println("1");
                JOptionPane.showMessageDialog(null, "为输入学号或姓名", "提醒", JOptionPane.QUESTION_MESSAGE);
            }
            String nameString=name.getText();
            boolean isNumeric=true;
            for (int i = 0; i < nameString.length(); i++) {
                if (!Character.isDigit(nameString.charAt(i))) {
                    isNumeric = false;
                }
            }
            if(isNumeric==true) {
                System.out.println("1");
                JOptionPane.showMessageDialog(null, "姓名不能全为数字", "提醒", JOptionPane.QUESTION_MESSAGE);
            }
            String sex;
            if(radioButton1.isSelected()) {
                sex="男";
            } else {
                sex="女";
            }
            if(Item.equals("")) {
                Item="三等";
            }
            Object[] info = {studentId.getText(),nameString,sex,Item,show.getText()};
            Model.addRow(info);
        }
        if(e.getSource()==edit) {
            return;
        }
    }
    private String Item;
    @Override
    public void itemStateChanged(ItemEvent e) {
        if(e.getStateChange() == 1) {
            String s = e.getItem().toString();
            Item=s;
            if(s.equals("一等")){
                show.setText("8000");
            } else if(s.equals("二等")) {
                show.setText("5000");
            } else if(s.equals("三等")) {
                show.setText("300");
            }
        }

    }
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
